<?php
class LogService extends Service {

    public static function header($type){
        $list = ModLog::getTblColumns($type);
        $header['os'] = array('text' => '渠道');
        foreach($list as $v){
            $header[$v['Field']] = array('text' => self::mapHeader($type, $v['Field']));
        }

        if(isset($header['GameAppID'])){
            unset($header['GameAppID']);
        }
        
        if(isset($header['goods_child_access'])){  //隐藏货币流水的获取子途径
        	unset($header['goods_child_access']);
        }
        
        if($type == 'bossFall' || $type == 'pickup' || $type == 'compose' || $type == 'appearanceUpgrade' || $type == 'equipSell' || $type == 'equipSwallow' || $type == 'slotStrengthen' || $type == 'equipSuit' || $type == 'runeUpgrade'
        || $type == 'shapeOpen' || $type == 'shapeUpgrade'){
        	$data = array();
        	$data['item_name'] = array('text' => '物品名称');
        	$data['item_step'] = array('text' => '物品阶数');
        	$data['item_color'] = array('text' => '物品品质');
        	$data['item_star'] = array('text' => '物品星级');
        	$header = self::wpjam_array_push($header,$data,'item_num');
        }
        
        if($type == 'shop'){
        	$data = array();
        	$data['goods_name'] = array('text' => '物品名称');
        	$data['goods_step'] = array('text' => '物品阶数');
        	$data['goods_color'] = array('text' => '物品品质');
        	$data['goods_star'] = array('text' => '物品星级');
        	$header = self::wpjam_array_push($header,$data,'goods_num');
        }
        
        if($type == 'market'){
        	$data = array();
        	$data['class_name'] = array('text' => '物品名称');
        	$data['class_step'] = array('text' => '物品阶数');
        	$data['class_color'] = array('text' => '物品品质');
        	$data['class_star'] = array('text' => '物品星级');
        	$header = self::wpjam_array_push($header,$data,'num');
        }
        
        if($type == 'achievement'){
        	$data = array();
        	$data['achievement_name'] = array('text' => '成就名称');
        	$data['achievement_desc'] = array('text' => '成就描述');
        	$header = self::wpjam_array_push($header,$data,'status');
        }
        
        if($type == 'bossFall' || $type == 'bossDeath'){
        	$data = array();
        	$data['boss_name'] = array('text' => 'Boss名称');
        	$data['boss_type'] = array('text' => 'Boss类型');
        	$data['boss_lv'] = array('text' => 'Boss等级');
        	$header = self::wpjam_array_push($header,$data,'ctime');
        }
        
        if($type == 'pickup'){
        	$data = array();
        	$data['boss_name'] = array('text' => 'Boss名称');
        	$data['boss_type'] = array('text' => 'Boss类型');
        	$data['boss_lv'] = array('text' => 'Boss等级');
        	$header = self::wpjam_array_push($header,$data,'item_id');
        }
        
        if($type == 'shapeOpen'){
        	$data = array();
        	$data['shape_name'] = array('text' => '幻形名称');
        	$header = self::wpjam_array_push($header,$data,'item_id');
        }
        
        if($type == 'shapeUpgrade' || $type == 'shapeDecompose'){
        	$data = array();
        	$data['shape_name'] = array('text' => '幻形名称');
        	$header = self::wpjam_array_push($header,$data,'new_exp');
        }
  
        $data = array();
        $data['ctime'] = $header['ctime'];
        $data['gamesrc'] = $header['gamesrc'];
        if($type != 'sendcoin' && $type != 'orders' && $type != 'bossFall' && $type != 'bossDeath' && $type != 'rank'){
        	$data['deviceid'] = $header['deviceid'];
        	$data['device'] = $header['device'];
        	unset($header['deviceid']);
        	unset($header['device']);
        }
        
        unset($header['ctime']);
        unset($header['gamesrc']);
        
        $header = self::wpjam_array_push($header,$data);

        return $header;
    }
    
    /**
     * 关联数组指定的Key之前插入元素的方法
     * @param unknown $array
     * @param string $data
     * @param string $key
     * @return multitype:
     */
    public static function wpjam_array_push($array, $data=null, $key=false){
    	$data  = (array)$data;
    	$offset  = ($key===false)?false:array_search($key, array_keys($array));
    	$offset  = ($offset)?$offset:false;
    	if($offset){
    		return array_merge(
    				array_slice($array, 0, $offset),
    				$data,
    				array_slice($array, $offset)
    		);
    	}else{  // 没指定 $key 或者找不到，就直接加到末尾
    		return array_merge($array, $data);
    	}
    }
    

    /**
     * 字典替换
     * @param $type     类型
     * @param $data     源数据
     * @return mixed    返回替换后的数据
     */
    public static function dictMap($type, $params, $data){
        $model = new ModLogDict();
        $dictMap = $model->getDictMap($type);

        foreach($dictMap as $v){
            $dictTmp = PubDict::dict($params['g'], $v['dict_type']);
            foreach($data as &$dv){
                if(isset($dv[$v['col_name']]) && isset($dictTmp[$dv[$v['col_name']]])){
                    $dv['origin_'.$v['col_name']] = $dv[$v['col_name']];
                    $dv[$v['col_name']] = $dictTmp[$dv[$v['col_name']]];
                }
            }
            unset($dv);
        }

        return $data;
    }

    
    
    
    public static function mapHeader($type, $k){
        $map = array(
        		'gamesrc'       => '游戏',
                'platform'      => '平台',
	            'openid'	    => '平台用户ID',
                'server'        => '游戏服',
	            'ctime'	        => '操作时间',
                'roleid'        => '角色ID',
                'rolename'      => '角色名',
                'level'         => '等级',
        		'sex'	        => '性别',
        		'country'	    => '国家',
        		'job'           => '职业',

                'logintime'     => '登录时间',
        		'loginouttime'  => '登出时间',
        	
        	    'packe'         => '包号',
        		'phone_model'   => '手机类型',
        		'system_version'=> '系统版本',
        		'phone_mac'     => 'mac物理地址',
        		'online_time'   => '在线时长(分钟)',
        		
        	    'grade'         => '等级',
        		
        		'currency_change'=> '货币变化值',
        		'change_after'   => '变化后剩余值',
        		'way'            => '途径',
        		'type'           => '流水类型',
        		
        		'goods_access'  => '获取途径',
        		'goods_child_access' => '获取子途径',
        		'goods_name'    => '物品名称',
        		'goods_id'    => '物品ID',
        		'goods_color'   => '物品品质',
        		'goods_star'    => '物品星级',
        		'goods_num'     => '物品数量',
        		'goods_step'    => '物品阶数',
        		'is_bind'       => '是否绑定',
        		
        		
        		'operation_type'=> '操作类型',

        	    'skill_grade'   => '技能（等级)',
        		'now_experience'=> '当前经验值',

        		'lastlevel'     => '历史等级',
        		'currentlevel'  => '当前等级',
        		'lastexp'       => '历史经验',
        		'currentexp'    => '当前经验',

        		'inlevel'       => '登入等级',
        		'outlevel'      => '登出等级',
        		'reason'        => '登出状态',

        		'cnumber'       => '变动数量',
        		'current'       => '历史数量',
        		'remain'        => '当前数量',

        		'action'        => '行为名称',
        		'transactionid' => '事件ID',

        		'coin'          => '货币变动数量',
        		'currentcoin'   => '历史货币数量',
        		'remaincoin'    => '当前货币数量',
        		'cointype'      => '货币类型',
        		'currency_type' =>'货币类型',
        		'use_num'       =>'消耗货币数量',
        		'goods_price'   =>'单价',
    
        
        		'itemid'        => '道具ID',
        		'itemname'      => '道具名称',
        		
        		'boosid' => 'Boss ID',
        		'boos_name' => 'Boss名字',
        		'boss_name' => 'Boss名字',
        		'boss_grade'=>'Boss等级',
        		'color'=>'物品品质',
        		
        		'part_id'=>'部位ID',
        		'part_name'=>'部位名称',
        		
        		'upgrade_time'=>'升级时间',
        		'now_grade'=>'当前等级',
        		'upgrade_experience'=>'升级所需经验',
        		
        		'faction_name'=>'帮派名称',
        		
        		'now_experience'=>'当前经验值',
        		'get_experience'=>'获得经验值',
        		'grade_experience'=>'升级经验',
        		'unreal_name'=>'幻形名字',
        		'unreal_star'=>'幻形星级',
        		'promote_time'=>'提升时间',
        		'unreal_rank'=>'幻形阶数',
        		
        		'level'=>'等级',
        		'device'=>'设备',
        		'deviceid'=>'设备号',
        		
        		'email'=>array(
        				'mail_type'=>'邮件类型',
        				'mail_sender'=>'发件人',
        				'mail_status'=>'邮件状态',
        				'mail_id'=>'邮件id',
        				'mail_title'=>'邮件标题',
        				'mail_content'=>'邮件内容',
        				'get_time'=>'接到时间',
        				'read_time'=>'读取时间',
        				'gain_time'=>'提取时间',
        				'mail_attach'=>'附件'
        		),

        		'goodscomp'     => array(
        				'Quality' => '石币消耗',
                ),
        		'pet'           => array(
        				'Quality' => '品质',
                ),
        		
        		'equWear'=>array(
        				'equ_after_name'=>'穿戴后装备名称',
        				'equ_after_color'=>'穿戴后物品品质',
        				'equ_after_star'=>'穿戴后物品星级',
        				'equ_after_attr'=>'穿戴后装备属性',
        				'equ_before_name'=>'穿戴前装备名称',
        				'equ_before_color'=>'穿戴前物品品质',
        				'equ_before_star'=>'穿戴前物品星级',
        				'equ_before_attr'=>'穿戴前装备属性'
        		),
        		'equSuit'=>array(
        				'equ_name'=>'穿戴装备名称',
        				'equ_star'=>'物品星级',
        				'forge_before_name'=>'套装名称',
        				'suit_sum'=>'套装件数',
        				'forge_add_attr'=>'锻造加成属性',
        		),
        		'runeUpgrade'=>array(
        				'upgrade_remain'=>'剩余符文精华',
        		),
        		'soulUpgrade'=>array(       				
        				'upgrade_remain'=>'剩余聚魂精华',
        		),
        		'stateUpgrade'=>array(
        				'state_name'=>'境界名称',
        		),
        		'fashionUpgrade'=>array(
        				'fashion_name'=>'时装名称',
        				'fashion_star'=>'时装星级',
        		),
        		'swordUpgrade'=>array(
        				'sword_name'=>'剑魂名称',
        				'sword_star'=>'剑魂星级',
        		),
        		'daily'=>array(
        				'get_experience'=>'获得经验',
        				'daily_type'=>'类型',
        		),
        		'sports'=>array(
        				'now_ranking'=>'本次排名',
        				'last_ranking'=>'上次排名',
        		),
        		'factionMember'=>array(
        				'join_time'=>'加入时间',
        				'exit_time'=>'退出时间',
        		),
        		'factionGrade'=>array(
        				'faction_grade'=>'帮派等级',
        		),
        		'factionCapital'=>array(
        				'capital_type'=>'流水类型',
        				'flow_type'=>'途径',
        				'capital_way'=>'资金变化值',
        				'currency_change'=>'变动后剩余值',
        		),
        		'factionRedpacket'=>array(
        				'send_money'=>'发送金额',
        				'send_num'=>'发送个数',
        				'send_time'=>'发送时间',
        		),
        		'surfaceWing'=>array(
        				'wing_type'=>'翅膀类型',
        		),
        		'surfaceMounts'=>array(
        				'mounts_type'=>'坐骑类型',
        		),
        		'task'=>array(
        				'task_id'=>'任务ID',
        				'task_name'=>'任务名称',
        				'last_id'=>'上个任务ID',
        				'last_name'=>'上个任务名称',
        				'task_status'=>'任务状态'
        		),
        		'orders'=>array(
        				'orderid'=>'平台订单号',
        				'g_orderid'=>'游戏订单号',
        				'channel'=>'充值渠道',
        				'fromamount'=>'充值金额',
        				'toamount'=>'发放货币',
        				'stime'=>'发放时间',
        				'status'=>'充值结果',
        				'first_pay'=>'是否首充'
        		),
        		'sendcoin'=>array(
        				'orderid'=>'平台订单号',
        				'g_orderid'=>'游戏订单号',
        				'channel'=>'充值渠道',
        				'fromamount'=>'充值金额',
        				'toamount'=>'发放货币',
        				'stime'=>'发放时间',
        				'status'=>'发放结果',
        		),
        		'bossDeath'=>array(
        				'ctime'=>'死亡时间',
        		),
        		'map_id'=>'地图ID',
        		'inst_type'=>'副本类型',
        		'vip_level'=>'VIP等级',
        		'power'=>'战力',
        		'reward_exp'=>'奖励经验',
        		'item_id'=>'掉落物品ID',
        		'item_num'=>'掉落物品数量',
        		'newtime'=>'复活时间',
        		'achievement'=>array(
        				'ach_id'=>'成就 id',
        				'status'=>'成就状态',
        		),
        		'compose'=>array(
        				'type'=>'合成类型',
        				'use_list'=>'合成消耗物品列表',
        				'item_id'=>'合成物品id'
        		),
        		'appearanceUpgrade'=>array(
        				'appearance_type'=>'外观类型',
        				'new_exp'=>'新经验值',
        				'new_grade'=>'新等级',
        				'item_id'=>'消耗物品 id'
        		),
        		'equipSell'=>array(
        				'get_coin'=>'出售获得铜钱',
        				'item_id'=>'出售物品 id'
        		),
        		'equipSwallow'=>array(
        				'get_exp'=>'吞噬获得经验',
        				'item_id'=>'吞噬物品 id'
        		),
        		'guild_id' => '帮派id',
        		'guild_name'=>'帮派名称',
        		'guild_level'=>'帮派等级',
        		'guildCapital'=>array(
        				'currency_change'=>'资金变化值',
        				'currency_remain'=>'变化后剩余值'
        		),
        		'guildMember'=>array(
        				'type'=>'类型',
        		),
        		'guildRedpacket'=>array(
        				'type'=>'红包来源',
        				'send_money'=>'发送金额',
        				'send_num'=>'发送个数',
        		),
        		'slotStrengthen'=>array(
        				'slot'=>'装备部位',
        				'item_id'=>'装备物品 id',
        				'new_exp'=>'新经验值',
        				'new_level'=>'新强化等级',
        		),
        		'equipWear'=>array(
        				'type'=>'穿戴类型',
        				'slot'=>'装备部位',
        				'last_id'=>'历史装备',
        				'new_id'=>'新的装备',
        		),
        		'equipInlay'=>array(
        				'slot'=>'装备部位',
        				'item_id'=>'穿戴装备',
        				'gem_id'=>'镶嵌宝石',
        		),
        		'equipSuit'=>array(
        				'slot'=>'装备部位',
        				'item_id'=>'穿戴装备 id',
        				'suit_type'=>'套装类型',
        		),
        		'rank'=>array(
        				'rank'=>'排名',
        				'vip_level'=>'VIP等级',
        				'profession'=>'职业',
        				'nums'=>'对应类型数值',
        				'type'=>'排行榜类型',
        		),
        		'runeUpgrade'=>array(
        				'use_exp'=>'符文经验消耗',
        				'item_id'=>'符文 id',
        				'new_level'=>'符文升级后等级',
        		),
        		'giftUse'=>array(
        				'item_id'=>'礼包 id',
        				'item_list'=>'礼包奖励物品列表',
        		),
        		'shapeOpen'=>array(
        				'item_id'=>'消耗物品 id',
        				'shape_id'=>'激活幻形 id',
        				'appearance_type'=>'外观类型',
        		),
        		'shapeUpgrade'=>array(
        				'item_id'=>'消耗物品 id',
        				'shape_id'=>'幻形 id',
        				'appearance_type'=>'外观类型',
        				'new_exp'=>'新经验值',
        				'new_grade'=>'新等级',
        				'item_num'=>'消耗物品数量',
        		),
        		'shapeDecompose'=>array(
        				'item_list'=>'消耗物品列表',
        				'shape_id'=>'幻形 id',
        				'appearance_type'=>'外观类型',
        				'new_exp'=>'新经验值',
        				'new_grade'=>'新等级',
        		),
        		'offline_exp'=>'经验',
        		'market'=>array(
        				'level'=>'等级',
        				'seller_id'=>'卖家角色ID',
        				'seller_name'=>'卖家名称',
        				'class_id'=>'物品ID',
        				'num'=>'物品数量',
        				'currency_type'=>'货币类型',
        				'price'=>'价格',
        		),
        		
        		
        );

        if(isset($map[$type][$k])){
            return $map[$type][$k];
        }else if(isset($map[$k])){
            return $map[$k];
        }else{
            return ucfirst($k);
        }
    }

    public static function data($type, $params, $export=false){
        if($export){
            $data   = ModLog::getLog($type, $params, false, true);
        }else{
            $data   = ModLog::getLog($type, $params);
            $cnt    = ModLog::getLog($type, $params, true);
        }

        $map = array();
        $map['g'] = $params['g'];
        $modChannel = new ModChannel();
        $channel_list = $modChannel->select($map);
        $channel_array = array();
        foreach ($channel_list as $key=>$val){
        	$channel_array[$val['tab']] = $val['channel_name'];
        }
        
        foreach($data as &$val){ 
        	if(isset($val['ctime'])){
        		$val['ctime'] = date('Y-m-d H:i:s',$val['ctime']);
        	}
        	if(isset($val['logintime'])){
        		$val['logintime'] = date('Y-m-d H:i:s',$val['logintime']);
        	}
        	if(isset($val['loginouttime'])){
        		$val['loginouttime'] = date('Y-m-d H:i:s',$val['loginouttime']);
        	}
        	if(isset($val['send_time'])){
        		$val['send_time'] = date('Y-m-d H:i:s',$val['send_time']);
        	}
        	if(isset($val['collect_time'])){
        		$val['collect_time'] = date('Y-m-d H:i:s',$val['collect_time']);
        	}
        	if(isset($val['stime'])){
        		$val['stime'] = date('Y-m-d H:i:s',$val['stime']);
        	}
        	if(isset($val['get_time']) && $val['get_time'] != 0){
        		$val['get_time'] = date('Y-m-d H:i:s',$val['get_time']);
        	}
        	if(isset($val['read_time']) && $val['read_time'] != 0){
        		$val['read_time'] = date('Y-m-d H:i:s',$val['read_time']);
        	}
        	if(isset($val['gain_time']) && $val['gain_time'] != 0){
        		$val['gain_time'] = date('Y-m-d H:i:s',$val['gain_time']);
        	}
        	if(isset($val['newtime']) && $val['newtime'] != 0){
        		$val['newtime'] = date('Y-m-d H:i:s',$val['newtime']);
        	}
        	if(isset($val['online_time'])){  //在线时长秒转化为分钟
        		$val['online_time'] = number_format($val['online_time'] / 60,2);        		
        	}
        	//platform
        	$val['os'] = $channel_array[$val['platform']];
        }
        unset($val);
        
        $colortypeList = PubDict::dict('mango', 'colortype');  //查询物品品质对应的字典
        
        if($type == 'goods' || $type == 'shop'){  //道具流水需要到ossdb库goods表查询 物品阶数、物品品质、物品星级
        	$data = self::goodsData($colortypeList,$data);
        }

        if($type == 'bossFall' || $type == 'pickup' || $type == 'compose' || $type == 'appearanceUpgrade' || $type == 'equipSell' || $type == 'equipSwallow' || $type == 'slotStrengthen' || $type == 'equipSuit' || $type == 'runeUpgrade'
        		|| $type == 'shapeOpen' || $type == 'shapeUpgrade'){
        	$data = self::itemData($colortypeList,$data);
        }
        
        if($type == 'market'){
        	$data = self::classData($colortypeList,$data);
        }
        
        if($type == 'compose'){ //处理合成消耗列表
        	$data = self::composeData($data);
        }
        
        if($type == 'equipWear'){ //装备穿戴日志 
        	$data = self::equipWearData($colortypeList,$data);
        }
        
        if($type == 'equipInlay'){
        	$data = self::equipInlayData($colortypeList,$data);
        }
        
        if($type == 'achievement'){  //查成就
        	$data = self::achievementData($data);
        }
        
        if($type == 'email'){ //邮件日志
        	$data = self::emailData($data);
        }
        
        if($type == 'giftUse'){ //礼包日志
        	$data = self::giftUseData($data);
        }
        
        if($type == 'bossFall' || $type == 'bossDeath' || $type == 'pickup'){  //BOSS相关日志
        	$data = self::bossData($data);
        }
        
        if($type == 'shapeOpen' || $type == 'shapeUpgrade'){  //幻形
        	$data = self::shapeData($data);
        }
        
        if($type == 'shapeDecompose'){ 
        	$data = self::shapeDecomposeData($data);
        }
        
        $data = self::dictMap($type,$params,$data);
        

        if($export){
            return $data;
        }else{
            return array('count'=>$cnt, 'data'=>$data);
        }
    }
    
    
    /**
     * 处理幻形相关日志的数据
     * @param unknown $data
     */
    public static function shapeDecomposeData($data){
    	$b_id_array = array();
    	$g_id_array = array();
    	foreach ($data as $key=>$val){
    		if($val['shape_id'] == ''){
    			continue;
    		}
    		$b_id_array[] = $val['shape_id'];
    		
    		$item_list_array = json_decode($val['item_list'],true);
    		foreach ($item_list_array as $k=>$v){
    			if($v['class_id'] == ''){
    				continue;
    			}
    			$g_id_array[] = $v['class_id'];
    		}
    	}
    	
    	$modUnreal = new ModUnreal();
    	$boss_data= $modUnreal->getInfo($b_id_array);
    	$new_boss_data = array();
    	foreach ($boss_data as $key=>$val){
    		$new_boss_data[$val['u_id']] = $val;
    	}
    	
    	$g_id_array = array_unique($g_id_array);

    	$modGoods = new ModGood();
    	$goods_data= $modGoods->getInfo($g_id_array);    	
    	$new_goods_data = array();
    	foreach ($goods_data as $key=>$val){
    		$new_goods_data[$val['g_id']]['name'] = $val['name'];
    		$new_goods_data[$val['g_id']]['quality'] = $val['quality'];
    		$new_goods_data[$val['g_id']]['stage'] = $val['stage'];
    		$new_goods_data[$val['g_id']]['star'] = $val['star'];
    	}
    	 
    	foreach($data as &$v){
    		$v['shape_name'] = $new_boss_data[$v['shape_id']]['name'];
    		
    		$item_list_array = json_decode($v['item_list'],true);
    		$item_list = '';
    		foreach ($item_list_array as $k=>$val){
    			$quality = $new_goods_data[$val['class_id']]['quality'];
    			$color = self::mapColor($quality);
    			$quality = $colortypeList[$quality];
    			$bind = '';
    			if($val['bind'] == 1){
    				$bind = '绑定';
    			}
    			if($val['bind'] == 0){
    				$bind = '不绑定';
    			}
    			 
    			$item_list .= '名称：<font color="'.$color.'">'.$new_goods_data[$val['class_id']]['name']. '</font>('.$bind.'); ID:'.$val['class_id'].'; 数量：'.$val['num'].'; 阶数:'.$new_goods_data[$val['class_id']]['stage'].'; 品质:'.$quality.'; 星级:'.$new_goods_data[$val['class_id']]['star'].'<br/>';
    		}
    		$v['item_list'] = $item_list;
    	}
    	unset($v);
    	 
    	return $data;
    }
    
    
    /**
     * 处理幻形相关日志的数据
     * @param unknown $data
     */
    public static function shapeData($data){
    	$b_id_array = array();
    	foreach ($data as $key=>$val){
    		if($val['shape_id'] == ''){
    			continue;
    		}
    		$b_id_array[] = $val['shape_id'];
    	}
    	$modUnreal = new ModUnreal();
    	$boss_data= $modUnreal->getInfo($b_id_array);
    	$new_boss_data = array();
    	foreach ($boss_data as $key=>$val){
    		$new_boss_data[$val['u_id']] = $val;
    	}
    	
    	foreach($data as &$v){
    		$v['shape_name'] = $new_boss_data[$v['shape_id']]['name'];    	
    	}
    	unset($v);
    	
    	return $data;
    }
    
    /**
     * 处理boss相关日志的数据
     * @param unknown $data
     */
    public static function bossData($data){
    	$typeList = self::bossTypeList();
    	$b_id_array = array();
    	foreach ($data as $key=>$val){
    		if($val['bossid'] == ''){
    			continue;
    		}
    		$b_id_array[] = $val['bossid'];
    	}
    	$modBoss = new ModBoss();
    	$boss_data= $modBoss->getInfo($b_id_array);
    	$new_boss_data = array();
    	foreach ($boss_data as $key=>$val){
    		$new_boss_data[$val['b_id']] = $val;
    	}
    	 
    	foreach($data as &$v){
    		$v['boss_name'] = $new_boss_data[$v['bossid']]['name'];
    		$v['boss_type'] = $typeList[$new_boss_data[$v['bossid']]['type']];
    		$v['boss_lv'] = $new_boss_data[$v['bossid']]['lv'];
    	}
    	unset($v);
    	 
    	return $data;
    }
    
    public static function bossTypeList(){
    	$typeList = array(
    			'201'	 => '世界boss',
    			'202'  => 'boss之家',
    			'203'  => '个人boss',
    			'204'  => '蛮荒之地',
    	);
    	return $typeList;
    }
    
    
    /**
     * 处理装备镶嵌日志 的数据
     * @param unknown $colortypeList 物品品质对应的字典
     * @param unknown $data
     */
    public static function equipInlayData($colortypeList,$data){
    	$item_id_array = array();
    	$gem_id_array = array();
    	foreach ($data as $key=>$val){
    		$item_id_array[] = $val['item_id'];
    		$gem_id_array[] = $val['gem_id'];
    	}
    	 
    	$modGoods = new ModGood();
    	
    	$item_id_data= $modGoods->getInfo($item_id_array);
    	$item_id_goods_data = array();
    	foreach ($item_id_data as $key=>$val){
    		$item_id_goods_data[$val['g_id']] = $val;
    	}
    	 
    	$gem_id_data= $modGoods->getInfo($gem_id_array);
    	$gem_id_goods_data = array();
    	foreach ($gem_id_data as $key=>$val){
    		$gem_id_goods_data[$val['g_id']] = $val;
    	}
    	 
    	foreach($data as &$v){
    		if($v['item_id'] != 0){
    			$item_id = $v['item_id'];
    			$item_step = $item_id_goods_data[$v['item_id']]['stage'];
    			$item_star = $item_id_goods_data[$v['item_id']]['star'];
    			$item_quality = $colortypeList[$item_id_goods_data[$v['item_id']]['quality']];
    			$item_color = self::mapColor($item_id_goods_data[$v['item_id']]['quality']);
    			$item_name = '<font color="'.$item_color.'">'.$item_id_goods_data[$v['item_id']]['name'].'</font>';
    			$v['item_id'] = '名称：'.$item_name.'； ID：'.$item_id.'； 阶数：'.$item_step.'； 品质：'.$item_quality.'； 星级：'.$item_star;
    		}
    	
    		if($v['gem_id'] != 0){
    			$gem_id = $v['gem_id'];
    			$gem_step = $gem_id_goods_data[$v['gem_id']]['stage'];
    			$gem_star = $gem_id_goods_data[$v['gem_id']]['star'];
    			$gem_quality = $colortypeList[$gem_id_goods_data[$v['gem_id']]['quality']];
    			$gem_color = self::mapColor($gem_id_goods_data[$v['gem_id']]['quality']);
    			$gem_name = '<font color="'.$gem_color.'">'.$gem_id_goods_data[$v['gem_id']]['name'].'</font>';
    			$v['gem_id'] = '名称：'.$gem_name.'； ID：'.$gem_id.'； 阶数：'.$gem_step.'； 品质：'.$gem_quality.'； 星级：'.$gem_star;
    		}
    	}
    	unset($v);
    	 
    	return $data;
    }
    
    /**
     * 处理装备穿戴日志的数据
     * @param unknown $colortypeList 物品品质对应的字典
     * @param unknown $data
     */
    public static function equipWearData($colortypeList,$data){
    	$last_id_array = array();
    	$new_id_array = array();
    	foreach ($data as $key=>$val){
    		$last_id_array[] = $val['last_id'];
    		$new_id_array[] = $val['new_id'];
    	}
    	
    	$modGoods = new ModGood();

    	$last_id_data= $modGoods->getInfo($last_id_array);
    	$last_id_goods_data = array();
    	foreach ($last_id_data as $key=>$val){
    		$last_id_goods_data[$val['g_id']] = $val;
    	}
    	
    	$new_id_data= $modGoods->getInfo($new_id_array);
    	$new_id_goods_data = array();
    	foreach ($new_id_data as $key=>$val){
    		$new_id_goods_data[$val['g_id']] = $val;
    	}
    	
    	foreach($data as &$v){
    		if($v['last_id'] != 0){
    			$last_id = $v['last_id'];
    			$last_step = $last_id_goods_data[$v['last_id']]['stage'];
    			$last_star = $last_id_goods_data[$v['last_id']]['star'];
    			$last_quality = $colortypeList[$last_id_goods_data[$v['last_id']]['quality']];
    			$last_color = self::mapColor($last_id_goods_data[$v['last_id']]['quality']);
    			$last_name = '<font color="'.$last_color.'">'.$last_id_goods_data[$v['last_id']]['name'].'</font>';
    			$v['last_id'] = '名称：'.$last_name.'； ID：'.$last_id.'； 阶数：'.$last_step.'； 品质：'.$last_quality.'； 星级：'.$last_star;
    		}
    		
    		if($v['new_id'] != 0){
    			$new_id = $v['new_id'];
    			$new_step = $new_id_goods_data[$v['new_id']]['stage'];
    			$new_star = $new_id_goods_data[$v['new_id']]['star'];
    			$new_quality = $colortypeList[$new_id_goods_data[$v['new_id']]['quality']];
    			$new_color = self::mapColor($new_id_goods_data[$v['new_id']]['quality']);
    			$new_name = '<font color="'.$new_color.'">'.$new_id_goods_data[$v['new_id']]['name'].'</font>';
    			$v['new_id'] = '名称：'.$new_name.'； ID：'.$new_id.'； 阶数：'.$new_step.'； 品质：'.$new_quality.'； 星级：'.$new_star;
    		}
    	}
    	unset($v);
    	
    	return $data;
    }
    
    /**
     * 处理那些需要根据物品id查询物品相关信息的日志数据
     * @param unknown $colortypeList 物品品质对应的字典
     * @param unknown $data
     */
    public static function itemData($colortypeList,$data){
    	$g_id_array = array();
    	foreach ($data as $key=>$val){
    		if($val['item_id'] == ''){
    			continue;
    		}
    		$g_id_array[] = $val['item_id'];
    	}
    	$modGoods = new ModGood();
    	$goods_data= $modGoods->getInfo($g_id_array);
    	$new_goods_data = array();
    	foreach ($goods_data as $key=>$val){
    		$new_goods_data[$val['g_id']] = $val;
    	}
    	
    	foreach($data as &$v){
    		$v['item_step'] = $new_goods_data[$v['item_id']]['stage'];
    		$v['item_color'] = $colortypeList[$new_goods_data[$v['item_id']]['quality']];
    		$v['item_star'] = $new_goods_data[$v['item_id']]['star'];
    		$color = self::mapColor($new_goods_data[$v['item_id']]['quality']);
    		$v['item_name'] = '<font color="'.$color.'">'.$new_goods_data[$v['item_id']]['name'].'</font>';
    	}
    	unset($v);
    	
    	return $data;
    }
    
    /**
     * 处理市场日志的数据
     * @param unknown $data
     */
    public static function classData($colortypeList,$data){
    	$g_id_array = array();
    	foreach ($data as $key=>$val){
    		if($val['class_id'] == ''){
    			continue;
    		}
    		$g_id_array[] = $val['class_id'];
    	}
    	$modGoods = new ModGood();
    	$goods_data= $modGoods->getInfo($g_id_array);
    	$new_goods_data = array();
    	foreach ($goods_data as $key=>$val){
    		$new_goods_data[$val['g_id']] = $val;
    	}
    	foreach($data as &$v){
    		$v['class_step'] = $new_goods_data[$v['class_id']]['stage'];
    		$v['class_color'] = $colortypeList[$new_goods_data[$v['class_id']]['quality']];
    		$v['class_star'] = $new_goods_data[$v['class_id']]['star'];
    		$v['class_name'] = empty($v['class_name'])?  $new_goods_data[$v['class_id']]['name'] : $v['class_name'] ;
    		$color = self::mapColor($new_goods_data[$v['class_id']]['quality']);
    		$v['class_name'] = '<font color="'.$color.'">'.$v['class_name'].'</font>';
    	}
    	unset($v);
    	 
    	return $data;
    }
    
    /**
     * 处理道具日志的数据
     * @param unknown $data
     */
    public static function goodsData($colortypeList,$data){
    	$g_id_array = array();
    	foreach ($data as $key=>$val){
    		if($val['goods_id'] == ''){
    			continue;
    		}
    		$g_id_array[] = $val['goods_id'];
    	}
    	$modGoods = new ModGood();
    	$goods_data= $modGoods->getInfo($g_id_array);
    	$new_goods_data = array();
    	foreach ($goods_data as $key=>$val){
    		$new_goods_data[$val['g_id']] = $val;
    	}
    	foreach($data as &$v){
    		$v['goods_step'] = $new_goods_data[$v['goods_id']]['stage'];
    		$v['goods_color'] = $colortypeList[$new_goods_data[$v['goods_id']]['quality']];
    		$v['goods_star'] = $new_goods_data[$v['goods_id']]['star'];
    		$v['goods_name'] = empty($v['goods_name'])?  $new_goods_data[$v['goods_id']]['name'] : $v['goods_name'] ;
    		$color = self::mapColor($new_goods_data[$v['goods_id']]['quality']);
    		$v['goods_name'] = '<font color="'.$color.'">'.$v['goods_name'].'</font>';
    	}
    	unset($v);
    	
    	return $data;
    }
    
    /**
     * 处理成就的日志
     * @param unknown $data
     */
    public static function achievementData($data){
    	$ach_id_array = array();
    	foreach ($data as $key=>$val){
    		if($val['ach_id'] == ''){
    			continue;
    		}
    		$ach_id_array[] = $val['ach_id'];
    	}
    	$modAchievement = new ModAchievement();
    	$achievement_data= $modAchievement->getInfo($ach_id_array);
    	$new_achievement_data = array();
    	foreach ($achievement_data as $key=>$val){
    		$new_achievement_data[$val['a_id']] = $val;
    	}
    	 
    	foreach($data as &$v){
    		$v['achievement_name'] = $new_achievement_data[$v['ach_id']]['achievement_name'];
    		$v['achievement_desc'] = $new_achievement_data[$v['ach_id']]['achievement_desc'];
    	}
    	unset($v);
    	
    	return $data;
    }
    
    /**
     * 处理礼包日志 的数据
     * @param unknown $data
     */
    public static function giftUseData($data){
    	$g_id_array = array();
    	foreach ($data as $v){
    		$attach_array = json_decode($v['item_list'],true);
    		foreach ($attach_array as $k=>$val){
    			if($val['class_id'] == ''){
    				continue;
    			}
    			$g_id_array[] = $val['class_id'];
    		}
    	}
    	$g_id_array = array_unique($g_id_array);
    	
    	$modGoods = new ModGood();
    	$goods_data= $modGoods->getInfo($g_id_array);
    	$new_goods_data = array();
    	foreach ($goods_data as $key=>$val){
    		$new_goods_data[$val['g_id']] = $val['name'];
    	}
    	
    	foreach ($data as &$v){
    		$attach_array = json_decode($v['item_list'],true);
    		$attach = '';
    		foreach ($attach_array as $k=>$val){
    			$bind = '';
    			if($val['bind'] == 1){
    				$bind = '绑定';
    			}
    			if($val['bind'] == 0){
    				$bind = '不绑定';
    			}
    			$attach .= $new_goods_data[$val['class_id']].'('.$bind.')'.'x'.$val['overlap']. '<br/>';
    		}
    		$v['item_list'] = $attach;
    	}
    	unset($v);
    	 
    	return $data;
    }
    
    /**
     * 处理邮件日志的数据
     * @param unknown $data
     */
    public static function emailData($data){
    	$g_id_array = array();
    	foreach ($data as $v){
    		$attach_array = json_decode($v['mail_attach'],true);
    		foreach ($attach_array as $k=>$val){
    			if($val['class_id'] == ''){
    				continue;
    			}
    			$g_id_array[] = $val['class_id'];
    		}
    	}
    	$g_id_array = array_unique($g_id_array);
    	 
    	$modGoods = new ModGood();
    	$goods_data= $modGoods->getInfo($g_id_array);
    	$new_goods_data = array();
    	foreach ($goods_data as $key=>$val){
    		$new_goods_data[$val['g_id']] = $val['name'];
    	}
    	
    	foreach ($data as &$v){
    		$attach_array = json_decode($v['mail_attach'],true);
    		$attach = '';
    		foreach ($attach_array as $k=>$val){
    			$bind = '';
    			if($val['bind'] == 1){
    				$bind = '绑定';
    			}
    			if($val['bind'] == 0){
    				$bind = '不绑定';
    			}
    			$attach .= $new_goods_data[$val['class_id']].'('.$bind.')'.'x'.$val['overlap']. '<br/>';
    		}
    		$v['mail_attach'] = $attach;
    	}
    	unset($v);
    	
    	return $data;
    }
    
    /**
     * 处理合成日志的数据
     * @param unknown $data
     * @return unknown
     */
    public static function composeData($data){
    	foreach ($data as $v){
    		$use_list_array = json_decode($v['use_list'],true);
    		foreach ($use_list_array as $k=>$val){
    			if($val['id'] == ''){
    				continue;
    			}
    			$g_id_array[] = $val['id'];
    		}
    	}
    	$g_id_array = array_unique($g_id_array);
    	
    	$modGoods = new ModGood();
    	$goods_data= $modGoods->getInfo($g_id_array);
    	$new_goods_data = array();
    	foreach ($goods_data as $key=>$val){
    		$new_goods_data[$val['g_id']]['name'] = $val['name'];
    		$new_goods_data[$val['g_id']]['quality'] = $val['quality'];
    		$new_goods_data[$val['g_id']]['stage'] = $val['stage'];
    		$new_goods_data[$val['g_id']]['star'] = $val['star'];
    	}
    	 
    	foreach ($data as &$v){
    		$use_list_array = json_decode($v['use_list'],true);
    		$use_list = '';
    		foreach ($use_list_array as $k=>$val){
    			$quality = $new_goods_data[$val['id']]['quality'];
    			$color = self::mapColor($quality);
    			$quality = $colortypeList[$quality];	
    			$bind = '';
    			if($val['bind'] == 1){
    				$bind = '绑定';
    			}
    			if($val['bind'] == 0){
    				$bind = '不绑定';
    			}
    			
    			$use_list .= '名称：<font color="'.$color.'">'.$new_goods_data[$val['id']]['name']. '</font>('.$bind.'); ID:'.$val['id'].'; 数量：'.$val['num'].'; 阶数:'.$new_goods_data[$val['id']]['stage'].'; 品质:'.$quality.'; 星级:'.$new_goods_data[$val['id']]['star'].'<br/>';
    		}
    		$v['use_list'] = $use_list;
    	}
    	unset($v);
    	
    	return $data;
    }
    
    public static function getcolorType(){
    	$game = PubBase::getCurrentGame();
    	return PubDict::dict($game, 'colortype');
    }
    

    public static function regHeader($params){}

    public static function regData($params){}

} 
